package com.wbp.cms.core.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.wbp.cms.client.common.domain.QRCodeDO;
import com.wbp.cms.client.common.query.QRCodeQuery;
import com.wbp.cms.client.common.service.QRCodeService;
import com.wbp.cms.client.result.Result;
import com.wbp.cms.core.dao.QRCodeDAO;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月9日 下午2:26:18
 */
@Service("qRCodeService")
public class QRCodeServiceImpl implements QRCodeService {

  /**
   * 
   */
  private static final long serialVersionUID = -3472638777591747394L;
  private static final Logger logger =Logger.getLogger(QRCodeServiceImpl.class) ;
  @Resource
  private QRCodeDAO  qrCodeDAO ;
  
  @Override
  public Result<Long> addQRCode(QRCodeDO qrCodeDO) {
    Preconditions.checkNotNull(qrCodeDO, "qrCodeDO:"+qrCodeDO+",不能为null") ;
    return Result.buildSuccess( this.qrCodeDAO.insert(qrCodeDO)  );
  }

   
  @Override
  public Result<Boolean> modifyQRCode(QRCodeDO qrCodeDO) {
    Preconditions.checkNotNull(qrCodeDO, "qrCodeDO:"+qrCodeDO+",不能为null") ;
    
    return Result.buildSuccess(this.qrCodeDAO.update(qrCodeDO) > 0 ) ; 
  }
   
  @Override
  public Result<QRCodeDO> load(Long qrCodeId) {
    Preconditions.checkNotNull(qrCodeId, "qrCodeId:"+qrCodeId+",不能为null") ;
    Preconditions.checkArgument( qrCodeId > 0 , "qrCodeId:"+qrCodeId+",应 >0 "); 
    
    return Result.buildSuccess(this.qrCodeDAO.load(qrCodeId)); 
  }
   
  @Override
  public Result<List<QRCodeDO>> query(QRCodeQuery qrCodeQuery) {
    Preconditions.checkNotNull(qrCodeQuery, "qrCodeQuery:"+qrCodeQuery+",不能为null") ;
    int count = this.qrCodeDAO.queryCount(qrCodeQuery) ;
    List<QRCodeDO> list = null ;
    if(count > 0 ){
       list = this.qrCodeDAO.query(qrCodeQuery) ;
    }
    return Result.buildSuccess(count, list ) ; 
  }
   
  @Override
  public Boolean deleteQRCode(Long qrCodeId) {
    logger.error("deleteQRCode entry qrCodeId:"+qrCodeId);
    return this.qrCodeDAO.delete(qrCodeId) > 0 ;
  }
  

  
}
